package android.FiltrosJava;

import java.awt.image.BufferedImage;
//import java.awt.image.BufferedImageOp;
//import java.awt.image.ConvolveOp;
//import java.awt.image.Kernel;
import java.awt.image.WritableRaster;

public class GlowingEdges extends FiltroConvolucao{	
	float[][] maskX = {
			{-1.0f, -2.0f, -1.0f},
			{0.0f, 0.0f, 0.0f},
			{1.0f, 2.0f, 1.0f}			
	};
	
	float[][] maskY = {
			{-1.0f, 0.0f, 1.0f},
			{-2.0f, 0.0f, 2.0f},
			{-1.0f, 0.0f, 1.0f}
	};
	
	public BufferedImage applyFilter(BufferedImage dst){		
		BufferedImage src = copiaImagem(dst); 
			
		dst = applyConvolve(dst,maskX,0);				
		src = applyConvolve(src,maskY,0);
				    	
    	int width = src.getWidth();
    	int height = src.getHeight();    	
		   	    	
    	WritableRaster raster_src = src.getRaster();
    	WritableRaster raster_dst = dst.getRaster();
    	int[] imageData_src = new int[raster_src.getNumBands()];
    	int[] imageData_dst = new int[raster_dst.getNumBands()];
	        	
    	for ( int y = 0; y < height; y++ ) {
    		for ( int x = 0; x < width; x++ ) {
    			raster_src.getPixel(x,y,imageData_src);
    			raster_dst.getPixel(x,y,imageData_dst);
    			for (int z = 0; z < 3; z++){
    				imageData_dst[z] = delimitaCor((int)Math.sqrt((imageData_src[z] * imageData_src[z]) + (imageData_dst[z] * imageData_dst[z])));    				
    			}
    			raster_dst.setPixel(x,y,imageData_dst);    			
    		}
    	} 
    	src = null; 	
    	return dst;
	}

}

